<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 收样管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<link href="css/public.css" rel="stylesheet" type="text/css">
	<link href="css/index.css" rel="stylesheet" type="text/css">

	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/receiveService.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/DatePicker/WdatePicker.js" defer="defer"></script>
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>

<div class="wrap100">
	<!--full begin-->
    <div class="full">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>收样快速搜索</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
                <div class="fr subMenu">
                	<ul>
                    	<li><a href="<%=basePath%>trade/sendList">寄样管理</a></li>
                        <li><a href="<%=basePath%>trade/receiveList" class="current">收样管理</a></li>
                    </ul>
                </div>
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
            <form:form method="get" name="serachForm" >
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>快递单号：                </td>
                <td><input type="text" name="expressNumber" id="expressNumber" value="${searchCond.expressNumber}" size="25" class="input" /></td>
                <td>按时间查询：</td>
                <td><input type="text" name="beginDate" id="beginDate" value="<fmt:formatDate value="${searchCond.beginDate}" pattern="yyyy-MM-dd"/>" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="input"/></td>
                <!-- 
                <td>结束时间：</td>
                <td><input type="text" name="endDate" id="endDate" value="<fmt:formatDate value="${searchCond.endDate}" pattern="yyyy-MM-dd"/>" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"  class="input"/></td>
                 -->                                
              </tr>
            </table>
                        
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>国家：</td>
                <td>
                	<select id="country" name="country">
                	<option value="">-- 快递国家 --</option>
					<c:forEach var="country" items="${countryList}">
					<option value="${country.codeName}">${country.codeName}</option>
					</c:forEach>
				  </select><script>$("country").value="${searchCond.country}";</script>
                </td>
                <td>业务员：</td>
                <td>
	                <select id="userId" name="userId">
	                <c:if test="${sessionScope.memberSessionInfo.userType.value eq '0'}">
					<option value="">-- 业务员 --</option>					
					</c:if>
					<c:forEach var="user" items="${userList}">
					<option value="${user.id}">${user.userName}</option>
					</c:forEach>
					</select>
					<c:if test="${sessionScope.memberSessionInfo.userType.value eq '0'}">
					<script>$("userId").value="${searchCond.userId}";</script>
					</c:if>
				</td>
				<td>快递公司：</td>
				<td>
                  <select id="expressCompanyId" name="expressCompanyId">
                  	<option value="">-- 快递公司 --</option>
					<c:forEach var="company" items="${companyList}"><option value="${company.id}">${company.codeName}</option></c:forEach>
				  </select><script>$("expressCompanyId").value="${searchCond.expressCompanyId}";</script>
				</td>
				<td>付款方式：</td>
				<td>
					<select id="paymentMethod" name="paymentMethod">
					<option value="">-- 付款方式 --</option>
					<option value="true">寄付</option>
					<option value="false">到付</option>
					</select>
					<script>$("paymentMethod").value="${searchCond.paymentMethod}";</script>
				</td>
                <td><input type="submit" style="background:url(images/search.gif);width:92px;height:25px;border:0;margin:0;" value="" /></td>
              </tr>
            </table>
			</form:form>
</div>
             
    		<!--寄样管理 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>收样管理</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightPropertyList">
            	<div class="title1">
                <table width="99%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#dfe5e9">
                  <tr>
                    <th width="3%" align="center"><input type="checkbox" name="allSelectId" id="allSelectId" onclick="judgmentChecjBox('allSelectId','id')" /></th>
                    <th width="5%" align="left">收件时间</th>
                    <th width="5%" align="left">快递公司</th>
                    <th width="8%" align="left">快递单号</th>
                    <th width="11%" align="left">物品</th>
                    <th width="3%" align="left">重量</th>
                    <th width="5%" align="left">费用</th>
                    <th width="5%" align="left">付款方式</th>
                    <th width="4%" align="left">业务员</th>
                    <th width="5%" align="left">国家</th>
                    <th width="10%" align="left">公司</th>
                    <th width="5%" align="left">联系人</th>
                    <th width="8%" align="left">电话</th>
                    <th width="13%" align="left">地址</th>
                    <th width="10%" align="left">备注</th>                   
                  </tr>
                  <!-- 
                </table>
              </div>
                <div class="list">
                  <table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#dfe5e9">
                   -->
                  	<c:forEach var="express" items="${receiveList}">
                    <tr>
                     <td width="3%"  align="center"><input type="checkbox" value="${express.id}" name="id"/></td>
                      <td width="5%"><fmt:formatDate value="${express.receiveDate}" pattern="yyyy-MM-dd"/></td>                                                     
                      <td width="5%" >${express.expressCompany.codeName}</td>
                      <td width="8%" >${express.expressNumber}</td>
                      <td width="11%" >${express.content}</td>
                      <td width="3%" >${express.weight}</td>
                      <td width="5%" >${express.price}</td>
                      <td width="5%" >${express.paymentMethod==null?'':(express.paymentMethod==true?'寄付':'到付')}</td>
                      <td width="4%" >${express.user.userName}</td>
                      <td width="5%" >${express.country}</td>
                      <td width="10%" >${express.company}</td>
                      <td width="5%" >${express.sender}</td>
                      <td width="8%" >${express.telphone}</td>
                      <td width="13%" >${express.address}</td>
                      <td width="10%" >${express.detail}</td>                                
                    </tr>
                   	</c:forEach>
					<c:if test="${empty receiveList}"><tr><td colspan="15" style="text-align:center">没有相关记录！</td></tr></c:if>                                     
                  </table>
                </div>
            </div>
            <!--寄样管理 end-->


            <!--统计 end-->
            <div class="total">
                <div class="fl Statistics">总数：<strong> ${searchStat.totalCount}</strong> 条
                <script type="text/javascript">
				var pageControl = new wpagebar('pageControl');
				pageControl.argName = "pageIndex";
				pageControl.pageCount = ${searchStat.pageCount};
				pageControl.load();
				</script>
                </div>
                <div class="fr Operating">
                
                    <ul>
                        <!-- <li><input name="复 制" type="button" class="button" value="复 制" /></li> -->
                        <li><input name="添 加" type="button" class="button" value="添 加" onclick="addExpress()"/></li>
                        <li><input name="修 改" type="button" class="button" value="修 改" onclick="editExpresses()"/></li>
                        <c:if test="${sessionScope.memberSessionInfo.userType.value eq '0'}">
                        <li><input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/></li>
                        </c:if>
                        <li><input name="导出EXCEL" type="button" class="button" value="导出EXCEL" onclick="exportExcel()"/></li>
                    </ul>
                
                
                </div>
            </div>
 
            <!--统计 end-->
    
    </div>
	<!--full end-->
    
    <div id="win_temp" style="display:none">
	<div id="winCon_1">
	<form>
	<table class="tabView" style="margin-top:5px">
		<tr><th width="80">快递单号：</th><td><input type="text" name="expressNumber0" id="expressNumber0" value="" maxlength="100"/>
			<input type="hidden" name="expressId0" id="expressId0" /></td>
			<th width="80">快递公司：</th><td>
			<select id="expressCompany0">
			<c:forEach var="company" items="${companyList}"><option value="${company.id}">${company.codeName}</option></c:forEach>
			</select></td>
		</tr>
		<tr><th>业务员：</th><td>
			<select id="user0">
			<c:forEach var="user" items="${userList}"><option value="${user.id}">${user.userName}</option></c:forEach>
			</select></td>			
		    <th>物品：</th><td><input type="text" name="content0" id="content0" maxlength="200"/></td>
		</tr>
		<tr><th>重量：</th><td>
			<input type="text" name="weight0" id="weight0" value=""maxlength="10" /></td>
			<th>费用：</th><td><input type="text" name="price0" id="price0" value="" maxlength="10"/></td></tr>
		</tr>
		<tr><th>收样日期：</th><td>
			<input type="text" name="receiveDate0" id="receiveDate0" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
			<th>联系人：</th><td><input type="text" name="sender0" id="sender0" value="" maxlength="100"/></td></tr>
		</tr>
		<tr><th>国家：</th><td>
			<select id="country0">
                	<c:forEach var="country" items="${countryList}">
					<option value="${country.codeName}">${country.codeName}</option>
					</c:forEach>
				  </select></td>
			<th>公司：</th><td><input type="text" name="company0" id="company0" value="" maxlength="100"/></td></tr>
		</tr>
		<tr><th>电话：</th><td>
			<input type="text" name="telphone0" id="telphone0" value="" maxlength="30"/></td>
			<th>付款方式</th><td>
				<select id="paymentMethod0">
				<option value="">-- 付款方式 --</option>
				<option value="true">寄付</option>
				<option value="false">到付</option>
				</select>
			</td></tr>
		</tr>
		<tr><th>地址：</th><td colspan="3">
			<input type="text" name="address0" id="address0" value="" size="80" maxlength="200"/></td>
		</tr>
		</tr>
		<tr><th>备注：</th><td><textarea name="detail0" id="detail0" rows="2" cols="70" maxlength="200"></textarea> </td></tr>
		<tr><td colspan="2" style="text-align:right;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitExpress()"/></td>
			<td colspan="2" style="text-align:left;height:"><input type="reset" value=" 重置 " class="btn1" value="reset"/></td>
		</tr>
	</table>
	</form>
	</div>
	</div>
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>


<script  type="text/javascript">
function exportExcel(){			
	var ids = getSelectedCheckBoxValues('id');
	if(ids == "")
		alert("请先选择要导出的信息！");
	else {
		window.open("<%=basePath%>trade/exportExcel?t=7&ids="+ids);
	}
}
function addExpress(){
	WIN.show('<font size=5>添加收样信息</font>',$('winCon_1'),{width:600,height:400});
}
function editExpresses(){
	var objs = document.getElementsByName("id");	
	var ids=0;
	var vas='';
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids++;
			vas=objs[i].value;			
		}
	}
	if(ids!=1){
		alert("请选择一条且只能选择一条信息进行编辑！");
		return ;
	}	
	if(vas==''){
		alert("请先选择要操作的信息");
		return ;
	}else{
		editExpress(vas);
	}	
}
function editExpress(id){
	WIN.show('<font size=5>修改收样信息</font>',$('winCon_1'),{width:600,height:400});
	receiveService.getReceiveExpressById(id,function(data){
		$('expressId0').value=data.id;
		$('expressNumber0').value=data.expressNumber;
		$('user0').value=data.user.id;
		$('expressCompany0').value=data.expressCompany.id;
		$('paymentMethod0').value=data.paymentMethod;
		$('content0').value=data.content;
		$('weight0').value=data.weight;
		$('price0').value=data.price;
		$('country0').value=data.country;
		$('company0').value=data.company;
		$('sender0').value=data.sender;
		$('telphone0').value=data.telphone;
		$('address0').value=data.address;
		$('receiveDate0').value=formatDate(data.receiveDate);
		$('detail0').value=data.detail;		
	})
}
function delExpress(id){
	if(confirm("删除收样信息，确定删除 ？")){
		WIN.showpg();
		receiveService.deleteReceiveExpress(id,{
			callback:function(f){WIN.closepg();alert("删除成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("删除失败，请重试");},
			errorHander:function(err){}
		})
	}
}
function delsellMultiple(){			
	var objs = document.getElementsByName("id");
	var ids='';	
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids+=objs[i].value+",";
		}
	}
	if(ids==''){
		alert("请先选择要操作的信息");
		return ;
	}
	ids = ids.substring(0,ids.length - 1);
	
	if(confirm("您确定要删除?")){
		if(ids == ""){
			alert("请先选择要删除的信息！");
			return false;
		}else{
			receiveService.deleteReceiveExpressByIds(ids,{
				callback:function(f){alert("删除成功");reload();},
				exceptionHandler:function(message){alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
}
function submitExpress(){
	var data={
		id:			$('expressId0').value,
		expressNumber:	$('expressNumber0').value,
		user:		{id:$('user0').value},
		expressCompany:	{id:$('expressCompany0').value},
		paymentMethod:$('paymentMethod0').value,
		content: $('content0').value.trim(),
		weight: $('weight0').value,
		price: $('price0').value,		
		country:	$('country0').value.trim(),
		company:	$('company0').value,
		sender:$('sender0').value,
		telphone:$('telphone0').value,				
		address:      $('address0').value,
		detail:$('detail0').value,
		receiveDate:  $('receiveDate0').value.trim()?new Date($('receiveDate0').value.trim().replace(/-/g,"/")):''		
	}
	
	if(''==data.expressNumber){alert('快递单号不能为空');return;}
	if(''==data.user.id){alert('请选择业务员');return;}
	if(''==data.expressCompany.id){alert('请选择快递公司');return;}
	
	if(''==data.id){
		submitExpress.data=data;		
		receiveService.existsExpressNumber(data.expressNumber,{
			callback:function(f){if(f){alert('此快递单号已经存在，请更改');}else{submit(submitExpress.data);}},
			exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");reload();},
			errorHander:function(err){}
		})
	}else{
		submit(data);
	}
}
function submit(data){
	WIN.close();
	WIN.showpg();
	receiveService.editReceiveExpress(data,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}

</script>
</body>
</html>
